//
//  PTStuLifeServiceHeaderBackView.m
//  PlanTech
//  生活服务-首页-头部底图
//  Created by ruifeng song on 2018/7/10.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "PTStuLifeServiceHeaderBackView.h"

@interface PTStuLifeServiceHeaderBackView()

@property(nonatomic,strong)UILabel *bottomLabel;

@end

@implementation PTStuLifeServiceHeaderBackView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self createView];
    }
    return self;
}

-(void)createView
{
    
    _headerBackImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    [self addSubview:_headerBackImageView];
    
    _maskingView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    _maskingView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    [_headerBackImageView addSubview:_maskingView];

    //我的发布
    _myReleaseButton = [[PTStuLifeServiceTopButton alloc]initButtonWithImage:[UIImage imageNamed:@"my_release_img"] btnTitle:@"我的发布"];
    _myReleaseButton.btnLabel.font = PTFONT_17;
    [_myReleaseButton setFrame:CGRectMake(12,TOP_HEIGHT-25,95, 20)];
    [_myReleaseButton.btnImageView setFrame:CGRectMake(0, 0, 15, 20)];
    _myReleaseButton.btnLabel.frame = CGRectMake(25, 0, 70, 20);
    [self addSubview:_myReleaseButton];
    
    //我的兼职
    _myPartJobButton = [[PTStuLifeServiceTopButton alloc]initButtonWithImage:[UIImage imageNamed:@"my_partjob_img"] btnTitle:@"我的兼职"];
    _myPartJobButton.btnLabel.font = PTFONT_17;
    [_myPartJobButton setFrame:CGRectMake(130,TOP_HEIGHT-25,95, 20)];
    [_myPartJobButton.btnImageView setFrame:CGRectMake(0, 0, 15, 20)];
    _myPartJobButton.btnLabel.frame = CGRectMake(25, 0, 70, 20);
    [self addSubview:_myPartJobButton];
    
    //发布
    _releaseButton = [[PTStuLifeServiceTopButton alloc]initButtonWithImage:[UIImage imageNamed:@"add_release_img"] btnTitle:nil];
    [_releaseButton setFrame:CGRectMake(ScreenWidth - 35,TOP_HEIGHT-27,30, 30)];
    [_releaseButton.btnImageView setFrame:CGRectMake(0, 2, 20, 20)];
    [self addSubview:_releaseButton];
    
    [self addSubview:self.headerView];
}

-(PTStuLifeServiceHeaderView *)headerView
{
    if (_headerView == nil) {
        
        _headerView = [[PTStuLifeServiceHeaderView alloc]initWithFrame:CGRectMake(0, TOP_HEIGHT, ScreenWidth,54) titleArray:[NSArray arrayWithObjects:@"代取快递",@"打印复印",@"捎饭带饭",@"超市代购", nil]];
        CGFloat buttonW = ScreenWidth/4;
        
        _bottomLabel = [[UILabel alloc]initWithFrame:CGRectMake(((buttonW - 60)/2), 54 - 3 - 8,60, 3)];
        _bottomLabel.backgroundColor = [UIColor whiteColor];
        _bottomLabel.layer.cornerRadius = 1.5;
        _bottomLabel.layer.masksToBounds = YES;
        [_headerView addSubview:_bottomLabel];
    }
    return _headerView;
}

-(void)updateUnderlineLocationWithTag:(NSInteger)pageTag
{
    CGFloat buttonW = ScreenWidth/4;
    CGFloat orginx = ((buttonW - 60)/2);
    
    [UIView animateWithDuration:0.5 animations:^{
       
        [self.bottomLabel setFrame:CGRectMake((buttonW * pageTag) + orginx, 54-3-8, 60, 3)];
        
    }];
   
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
